<%@ page import="com.xpy.utils.ConnSqlServer" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.xpy.entity.Diary" %><%--
  Created by IntelliJ IDEA.
  User: 2314238429
  Date: 2024/4/9
  Time: 12:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>main</title>
    <link rel="stylesheet" href="./css/style2.css">
</head>
<body>
    <%@include file="head.jsp" %>
    <%
        Diary diary = new Diary();
        Connection conn = ConnSqlServer.getConnection();
        PreparedStatement pstm = conn.prepareStatement("select * from diary where id=?");
        pstm.setInt(1, 1);
        ResultSet rs = pstm.executeQuery();
        if(rs.next()){
            diary.setTitle(rs.getString("title"));
            diary.setContent(rs.getString("content"));
            diary.setWdate(rs.getDate("wdate"));
            diary.setUserId(rs.getLong("userid"));
            PreparedStatement pstm2 = conn.prepareStatement("select name from users where id=?");
            pstm2.setLong(1,diary.getUserId());
            ResultSet rs2 = pstm2.executeQuery();
            if(rs2.next()){
            String username = rs2.getString("name");
    %>
    <div class="index-container">
        <h4 class="diary-title"><%= diary.getTitle()%></h4>
        <p>作者：<%= username%>&nbsp;&nbsp;&nbsp;时间：<%= diary.getWdate()%>&nbsp;&nbsp;&nbsp;浏览次数：50次</p>
        <p class="content"><%= diary.getContent()%></p>
    </div>
    <%  } else {
            out.print("没找到用户名");
        }
        } else {
            out.print("没有记录");
        }
        rs.close();
        pstm.close();
        conn.close();
    %>
    <%@ include file="bottom.jsp" %>
</body>
</html>
